package com.software.library_conquer;

import android.app.Activity;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.TextView;

import com.qozix.tileview.TileView;

public class TileViewActivity extends Activity {

	private TileView tileView;
	private TextView titleText;
	LinearLayout parent;

	@Override
	public void onCreate( Bundle savedInstanceState ) {
		super.onCreate( savedInstanceState );
		requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_main);
        tileView = new TileView( this );
        LinearLayout main_layout = (LinearLayout)findViewById(R.id.main_layout);
        main_layout.addView(tileView);
		titleText = (TextView)findViewById(R.id.navigation_title);
		parent = (LinearLayout)findViewById(R.id.main_layout);
	}
	
	@Override
	public void onPause() {
		super.onPause();
		tileView.clear();
	}

	@Override
	public void onResume() {
		super.onResume();
		tileView.resume();
	}

	@Override
	public void onDestroy() {
		super.onDestroy();
		tileView.destroy();
		tileView = null;
	}
	
	public TileView getTileView(){
		return tileView;
	}
	public TextView getTitleText() { return titleText; }
	public void showmenu(PopupWindow popupWindow){
		popupWindow.showAtLocation(parent, Gravity.BOTTOM, 0, 0);
	}

	/**
	 * This is a convenience method to moveToAndCenter after layout (which won't happen if called directly in onCreate
	 * see https://github.com/moagrius/TileView/wiki/FAQ
	 */
	public void frameTo( final double x, final double y ) {
		getTileView().post( new Runnable() {
			@Override
			public void run() {
				getTileView().moveToAndCenter( x, y );
			}			
		});		
	}
}
